﻿using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace PengSW.Script
{
    public class TriggerScript : INotifyPropertyChanged
    {
        public string Key { get => _Key; set { if (_Key == value) return; _Key = value; OnPropertyChanged(nameof(Key)); } }
        private string _Key;

        public string Script { get => _Script; set { if (_Script == value) return; _Script = value; OnPropertyChanged(nameof(Script)); } }
        private string _Script;

        public IAction Action { get => _Action; private set { if (_Action == value) return; _Action = value; OnPropertyChanged(nameof(Action)); } }
        private IAction _Action;

        public void Compile()
        {
            Action = null; 
            Action = ScriptHelper.CreateScriptObject<IAction>(Script);
        }

        private void OnPropertyChanged([CallerMemberName] string aPropertyName = null) => PropertyChanged(this, new PropertyChangedEventArgs(aPropertyName));
        public event PropertyChangedEventHandler PropertyChanged;
    }
}
